package net.huashitong.Indicators.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.utils.ObjectUtils;
import com.sun.tools.javah.Gen;
import net.huashitong.Indicators.entity.AreaCode;
import net.huashitong.Indicators.filter.AreaCodeFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class AreaCodeDao extends StringDao<AreaCode> {

    /**
     * 条件查询
     * @param filter
     * @return
     */
    public List<AreaCode> queryAreaCode(AreaCodeFilter filter){
        GenericQuery query = createQuery("obj");
        if(ObjectUtils.isNotBlank(filter.getAreaName())){
            query.append(" and obj.areaCode = :areaCode ").setParam("areaCode", filter.getAreaCode());
        }
        if(ObjectUtils.isNotBlank(filter.getAreaName())){
            query.append(" and obj.areaName = :areaName ").setParam("areaName", filter.getAreaName());
        }
        return query.listResult();
    }

    public List<AreaCode> getCitysByParentCode(String code)
    {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.parentCode=:parentCode").setParam("parentCode",code);
        return query.listResult();
    }

    public void deleteAreaCode()
    {
        GenericQuery delete= create(" delete from  AreaCode  ");

        delete.executeUpdate();
    }



}
